function e(e) {
    return e && e.__esModule ? e : {
        default: e
    };
}

function t(e, t) {
    var a = e, n = "", i = void 0, o = void 0;
    if (1 == +t.id) return "/pages/website/index/index?sid=" + t.sid;
    var r = a.find(function(e) {
        return +e.modid == +t.modid;
    });
    return i = r ? r.modtemplate : "", n = Object.keys(t).map(function(e) {
        return e + "=" + t[e];
    }).join("&"), o = 1 == +t.modid ? i : 4 == +t.modid ? "link" === t.op ? ("services_project" === t.model ? "project" : "user") + "/view/view" : "list/list" : "link" === t.op ? "view/view" : "list/list", 
    "/pages/model/" + i + "/" + o + "?" + n;
}

function a(e) {
    var t = getApp().globalData, a = t.fromuid, n = t.appid;
    c.default.site.site.push({
        data: {
            appid: n,
            node: "sharesite",
            sid: e,
            fromuid: a
        }
    }).then(function(e) {
        console.log(e);
    });
}

function n(e) {
    if ("object" !== (void 0 === e ? "undefined" : i(e)) || !e || e instanceof Promise || e instanceof Map || e instanceof Set || e instanceof Function || e instanceof Date || e instanceof RegExp) return e;
    if (e instanceof Array) return e.map(function(e) {
        return n(e);
    });
    var t = Object.create(e.__proto__);
    return Object.keys(e).reduce(function(t, a) {
        return "object" === i(e[a]) ? t[a] = n(e[a]) : t[a] = e[a], t;
    }, t);
}

Object.defineProperty(exports, "__esModule", {
    value: !0
});

var i = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(e) {
    return typeof e;
} : function(e) {
    return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e;
};

exports.deepClone = n;

var o = e(require("../public/utils/util")), r = require("../public/utils/api-signature"), s = e(require("./config")), c = e(require("./api2")), d = e(require("./throttle")), u = e(require("./debounce")), p = e(require("../public/utils/authorize")), l = !1, f = !1;

exports.default = Object.assign({}, o.default, {
    createModelUrl: t,
    collectFormid: function(e) {
        var t = getApp().globalData, a = t.appid, n = t.app;
        if (e) return new Promise(function(t, i) {
            c.default.v4.weapp.collectformid({
                data: {
                    formid: e,
                    app: n,
                    appid: a
                }
            }).then(function(e) {
                console.log("已收集formid");
            });
        });
    },
    collectFromData: function(e) {
        var t = e.fromuid, a = e.source, n = getApp(), i = n.globalData, o = i.fromuid, r = i.fromapp;
        n.globalData.fromuid = t || o || "", n.globalData.fromapp = a || r || "";
    },
    collectSiteCreatData: function(e) {
        var t = e.node, a = e.pid, n = void 0 === a ? 0 : a, i = e.params, o = void 0 === i ? {} : i, r = e.sid, s = void 0 === r ? 0 : r, d = getApp();
        return new Promise(function(e, a) {
            d.getTokens().then(function(i) {
                i.accesstoken, c.default.site.site.recordcreatestep({
                    data: {
                        node: t,
                        pid: n,
                        params: o,
                        sid: s
                    }
                }).then(function(t) {
                    e(t);
                }).catch(function(e) {
                    a(e);
                });
            });
        });
    },
    updateNavBarTitle: function(e, t) {
        var a = t.find(function(t) {
            return t.model.navid === e;
        });
        a && wx.setNavigationBarTitle({
            title: a.title
        });
    },
    updateViewSiteStatus: function() {
        var e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : "exit", t = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : "", a = getApp(), n = a.globalData, i = n.appid;
        if (n.tokens.accesstoken) {
            var o = "view" === e ? {
                appid: i,
                sid: t,
                op: e
            } : {
                appid: i,
                op: e
            };
            c.default.site.site.viewingsite({
                data: o
            }).then(function(t) {
                "exit" === e && (a.globalData.fromuid = "", a.globalData.fromapp = "");
            });
        }
    },
    uploadMultipleImages: function(e) {
        if (e && e.length) {
            wx.showLoading({
                title: "上传图片中..."
            });
            var t = e.map(function(e) {
                return c.default.site.attachment.upload({
                    data: {
                        file: e,
                        recordid: ""
                    },
                    upload: "file"
                });
            });
            return Promise.all(t).then(function(e) {
                wx.hideLoading();
                var t = [];
                return e.forEach(function(e) {
                    t.push({
                        aid: e.fieldid,
                        source: e.url
                    });
                }), e.length !== t.length && wx.showModal({
                    content: e.length - t.length + "上传失败",
                    showCancel: !1
                }), t;
            }, wx.hideLoading);
        }
        return Promise.reject("文件路径错误");
    },
    showQrcode: function(e) {
        var t = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : "preview", n = getApp(), i = e.redirect;
        return new Promise(function(o, r) {
            n.getTokens().then(function(r) {
                var s = r.accesstoken, c = r.uid, d = void 0;
                if ("thirdparty" === i) d = "http://ibosapp.oss-cn-hangzhou.aliyuncs.com/site/sitehome.png?timestamp=" + Date.now(); else {
                    var u = e.modid, p = "https://api.xcxzhan.com/site/code/sitev2";
                    d = 5 == +u ? p + "?accesstoken=" + s + "&sid=" + e.sid + "&navid=" + e.navid + "&catid=" + e.catid + "&caseid=" + e.caseid + "&type=" + e.modid + "&op=" + e.op + "&app=" + (e.app || n.globalData.app) + "&appid=" + (e.appid || n.globalData.appid) + "&fromuid=" + c + "&timestamp=" + Date.now() : 4 == +u ? p + "?accesstoken=" + s + "&sid=" + e.sid + "&navid=" + e.navid + "&catid=" + e.catid + "&id=" + e.id + "&type=" + e.modid + "&model=" + e.model + "&level=" + e.level + "&op=" + e.op + "&app=" + (e.app || n.globalData.app) + "&appid=" + (e.appid || n.globalData.appid) + "&fromuid=" + c + "&timestamp=" + Date.now() : p + "?accesstoken=" + s + "&sid=" + e.sid + "&navid=" + e.navid + "&catid=" + e.catid + "&cid=" + e.cid + "&type=" + e.modid + "&op=" + e.op + "&app=" + (e.app || n.globalData.app) + "&appid=" + (e.appid || n.globalData.appid) + "&fromuid=" + c + "&timestamp=" + Date.now();
                }
                a(e.sid), "getUrl" !== t ? wx.previewImage({
                    urls: [ d ]
                }) : o(d);
            });
        });
    },
    formatSidebarNavUrl: function(e, a) {
        for (var n = s.default.model, i = 0; i < e.length; i++) {
            var o = e[i].model, r = {
                sid: e[i].sid,
                id: e[i].id,
                modid: o.modid,
                navid: o.navid,
                catid: o.catid,
                cid: o.cid
            };
            e[i].navUrl = t(n, r), e[i].navid === a && (e[i].isSelected = !0);
        }
        return e;
    },
    getCardInfo: function() {
        var e = getApp(), t = (0, r.generateHeaderParams)(), a = t.token, n = t.platform, i = t.createtime;
        e.getTokens().then(function(t) {
            t.accesstoken, c.default.minicard.card.viewv2({
                header: {
                    createtime: i,
                    platform: n,
                    token: a
                },
                data: {
                    isdefault: 1
                }
            }).then(function(t) {
                e.globalData.card = t.card;
            });
        });
    },
    getBargainShareImageUrl: function(e) {
        var t = getApp();
        return new Promise(function(a, n) {
            t.getTokens().then(function(t) {
                var n = "https://api.xcxzhan.com/site/code/sharebargain?accesstoken=" + t.accesstoken + "&" + Object.keys(e).map(function(t) {
                    return t + "=" + e[t];
                }).join("&") + "&timestamp=" + Date.now();
                a(n);
            });
        });
    },
    getGrouponShareImageUrl: function(e) {
        var t = getApp();
        return new Promise(function(a, n) {
            t.getTokens().then(function(t) {
                var n = "https://api.xcxzhan.com/site/code/sharegroupon?accesstoken=" + t.accesstoken + "&" + Object.keys(e).map(function(t) {
                    return t + "=" + e[t];
                }).join("&") + "&timestamp=" + Date.now();
                a(n);
            });
        });
    },
    getVersionIsReadStatus: function(e) {
        return new Promise(function(t, a) {
            c.default.site.agent.getisreadversion({
                data: {
                    app: "site",
                    version: e
                }
            }).then(function(e) {
                t(e);
            });
        });
    },
    getLotteryShareImageUrl: function(e) {
        return getApp().getTokens().then(function(t) {
            return "https://api.xcxzhan.com/site/code/lottery?accesstoken=" + t.accesstoken + "&" + Object.keys(e).map(function(t) {
                return t + "=" + e[t];
            }).join("&") + "&timestamp=" + Date.now();
        }).catch(function(e) {
            console.log("err", e);
        });
    },
    loadVserionHistory: function() {
        return new Promise(function(e, t) {
            wx.request({
                url: "https://oss.ibos.cn/common/json/site/history.json?timestamp=" + Date.now(),
                success: function(t) {
                    var a = t.data;
                    e(a);
                },
                fail: function(e) {
                    t(e);
                }
            });
        });
    },
    saveShareRecord: a,
    saveCallRecord: function(e) {
        var t = getApp().globalData.fromuid;
        c.default.site.site.push({
            data: {
                node: "call",
                sid: e,
                fromuid: t
            }
        }).then(function(e) {
            console.log(e);
        });
    },
    savePaymentRecord: function(e) {
        var t = getApp().globalData.fromuid;
        c.default.site.site.push({
            data: {
                node: "payproductorder",
                sid: e,
                fromuid: t
            }
        }).then(function(e) {
            console.log(e);
        });
    },
    pushRadarNews: function(e, t, a, n) {
        var i = getApp().globalData.fromuid;
        c.default.site.site.push({
            data: {
                node: e,
                sid: t,
                fromuid: i,
                timestamp: n,
                params: a
            }
        }).then(function(e) {
            console.log(e);
        });
    },
    pushWatchVideoEvent: function(e, t, a) {
        var n = getApp().globalData.fromuid;
        return new Promise(function(i, o) {
            c.default.site.site.push({
                data: {
                    node: "watchvideo",
                    sid: e,
                    fromuid: n,
                    timestamp: t,
                    params: a
                }
            }).then(function(e) {
                i(e);
            }).catch(function(e) {
                o(e);
            });
        });
    },
    throttle: d.default,
    debounce: u.default,
    setTheme: function(e) {
        var t = e.character, a = e.theme;
        wx.setNavigationBarColor({
            frontColor: "#" + (t || "000000"),
            backgroundColor: "#" + (a || "ffffff")
        });
    },
    countDown: function(e, t, a, n) {
        var i = 0;
        !function o() {
            (i += t) > e ? "function" == typeof n && n(e) : setTimeout(function() {
                "function" == typeof a && a(i, e), o();
            }, 1e3 * t);
        }();
    },
    saveInternetImgToLocal: function(e) {
        return wx.showLoading({
            title: "保存中.."
        }), new Promise(function(t, a) {
            wx.downloadFile({
                url: e,
                success: function(e) {
                    var n = e.tempFilePath;
                    wx.saveImageToPhotosAlbum({
                        filePath: n,
                        success: function(e) {
                            wx.hideLoading(), /ok/g.test(e.errMsg) ? t(n) : a("保存图片到本地出现错误");
                        },
                        fail: function() {
                            wx.hideLoading(), a("保存图片到本地出现错误");
                        }
                    });
                },
                fail: function() {
                    wx.hideLoading(), a("下载图片出现错误");
                }
            });
        });
    },
    saveOriginSiteData: function() {
        var e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
        return new Promise(function(t, a) {
            var n = getApp().globalData.originSite, i = n.sid, o = n.name;
            if (i) wx.showModal({
                content: "请返回“" + o + "”官网后，再搜索访问当前官网",
                showCancel: !1,
                confirmText: "我知道了"
            }), a("暂时不支持访问嵌套官网"); else {
                var r = getCurrentPages().length - 1;
                getApp().globalData.originSite = Object.assign({}, e, {
                    pageindex: r
                }), t(getApp().globalData.originSite);
            }
        });
    },
    deleteOriginSiteData: function() {
        var e = getApp().globalData.originSite, t = e.sid, a = e.pageindex, n = getCurrentPages().length - 1;
        t && n === a && (getApp().globalData.originSite = {});
    },
    deepClone: n,
    savePhotoToAlbum: function(e) {
        return new Promise(function(t, a) {
            wx.saveImageToPhotosAlbum({
                filePath: e,
                success: t,
                fail: function(e) {
                    return p.default.writePhotosAlbum(e, t, a);
                }
            });
        });
    },
    getNow: function() {
        return !l && getApp().globalData.isIniOS ? new Date(Date.now() + 288e5) : new Date();
    },
    getDate: function() {
        var e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : 0;
        return !f && getApp().globalData.isIniOS ? new Date(Date.now() + 288e5 + e) : new Date(Date.now() + e);
    },
    backToStackPage: function(e) {
        for (var t = getCurrentPages(), a = 0, n = t.length - 1; n >= 0; n--) RegExp(e).test(t[n].route) && (a = t.length - 1 - n);
        return a > 0 && wx.navigateBack({
            delta: a
        }), a > 0;
    }
});